package show.hkl.remote.demo;


import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

//Point泛型类的实现
class Point<T> {
    private T x, y;

    public T getX() {
        return x;
    }

    public void setX(T x) {
        this.x = x;
    }

    public T getY() {
        return y;
    }

    public void setY(T y) {
        this.y = y;
    }

}

//PointImpl类的实现
public class PointImpl extends Point<Integer> {

    public static void main(String[] args) {
        Class<?> clazz = PointImpl.class;
        Type type = clazz.getGenericSuperclass();


        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;

            //返回表示此类型实际类型参数的 Type 对象的数组
            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
            for (Type parameterArgType : actualTypeArguments) {
                Class parameterArgClass = (Class) parameterArgType;
                System.out.println("填充类型为：" + parameterArgClass.getName());
            }

            //返回 Type 对象，表示声明此类型的类或接口。
            Type type1 = parameterizedType.getRawType();
            Class class22 = (Class) type1;
            System.out.println(" PointImpl的父类类型为：" + class22.getName());

        }
    }
}